<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<!--生产状态编辑模态框-->
<div class="modal fade" id="modal-edit">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑生产状态</h4>
            </div>
            <div class="modal-body" style="height: 200px">
                <form id="editForm" class="form-horizontal">
                    <input type="hidden" name="proId">
                    <input type="hidden" name="id">
                    <!--<input type="hidden" name="code">-->
                    <div class="col-md-12">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">项目编号</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="code" readonly placeholder="项目编号">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">项目名称</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="name" readonly placeholder="项目名称">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">生产状态</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="proProductionStatus" title="">
                                        <option value="" selected="selected">全部</option>
                                        <option value="-1">无状态</option>
                                        <option value="1">未开始</option>
                                        <option value="2">执行中</option>
                                        <option value="3">已完成</option>
                                        <option value="4">取消</option>
                                        <option value="5">暂缓</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">备注</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="proRemark" autocomplete="off"
                                           placeholder="备注">
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-edit">提交</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<!--物控状态编辑模态框-->
<div class="modal fade" id="modal-mc-edit">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑物控状态</h4>
            </div>
            <div class="modal-body" style="height: 540px">
                <form id="editMcForm" class="form-horizontal">
                    <input type="hidden" name="proId">
                    <input type="hidden" name="id">
                    <div class="col-md-12">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">项目编号</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="code" readonly placeholder="项目编号">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">项目名称</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="name" readonly placeholder="项目名称">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">物控科原料状态
                                </label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="proMatStatus" title="">
                                        <option value="">无状态</option>
                                        <option value="1">正常提报</option>
                                        <option value="2">暂不提报</option>
                                        <option value="3">部分提报</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">物控科外购件状态
                                </label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="proPurStatus" title="">
                                        <option value="">无状态</option>
                                        <option value="1">正常提报</option>
                                        <option value="2">暂不提报</option>
                                        <option value="3">部分提报</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">物控科外协件状态
                                </label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="proSubcontractStatus" title="">
                                        <option value="">无状态</option>
                                        <option value="1">正常提报</option>
                                        <option value="2">暂不提报</option>
                                        <option value="3">部分提报</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">外购需求日期
                                </label>
                                <div class="col-sm-10">
                                    <input name="proPurchaseDemandDate" class="form-control datepicker"  readonly maxlength="255"/>
                                </div>
                            </div>
                        </div>

                    </div>
                </form>
            </div>
            <div class="modal-footer" >
                <button type="button" class="btn btn-info" id="btn-mc-edit">提交</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>

<section class="content-header"><h1>生产状态编辑</h1></section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label>项目编号</label>
                                    <input type="text" name="proCode" class="form-control" placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label>项目名称</label>
                                    <input type="text" name="name" class="form-control" placeholder="请输入项目名称">
                                </div>
<!--                                <div class="form-group">-->
<!--                                    <label>生产状态</label>-->
<!--                                    <select name="status" class="form-control">-->
<!--                                        <option value="-1" selected="selected">未完成</option>-->
<!--                                        <option value="0">项目取消</option>-->
<!--                                        <option value="3">项目暂停</option>-->
<!--                                        <option value="4">已完成</option>-->
<!--                                        <option value="">全部</option>-->
<!--                                    </select>-->
<!--                                </div>-->
                                <div class="form-group">
                                    <label>生产状态</label>
                                    <select name="proProductionStatus" class="form-control">
                                        <option value="" selected="selected">全部</option>
                                        <option value="-1">无状态</option>
                                        <option value="1">未开始</option>
                                        <option value="2">执行中</option>
                                        <option value="3">已完成</option>
                                        <option value="4">取消</option>
                                        <option value="5">暂缓</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>物控科原料状态</label>
                                    <select name="proMatStatus" class="form-control">
                                        <option value="" selected="selected">全部</option>
                                        <option value="0">无状态</option>
                                        <option value="1">正常提报</option>
                                        <option value="2">暂不提报</option>
                                        <option value="3">部分提报</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>物控科外购件状态</label>
                                    <select name="proPurStatus" class="form-control">
                                        <option value="" selected="selected">全部</option>
                                        <option value="0">无状态</option>
                                        <option value="1">正常提报</option>
                                        <option value="2">暂不提报</option>
                                        <option value="3">部分提报</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>物控科外协件状态</label>
                                    <select name="proSubcontractStatus" class="form-control">
                                        <option value="" selected="selected">全部</option>
                                        <option value="0">无状态</option>
                                        <option value="1">正常提报</option>
                                        <option value="2">暂不提报</option>
                                        <option value="3">部分提报</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label class="">外购需求日期</label>
                                        <input name="startDate" class="form-control datepicker"  readonly/>
                                        至
                                        <input name="endDate" class="form-control datepicker"  readonly/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    /** 表格 */
    var table, state = ['无状态', '执行中', '未开始', '暂缓', '已完成','取消'];
    var color = ['label-default', "label-warning", "label-info", "label-danger", "label-success"];
    var color1 = ['', "label-warning", "label-warning", "label-danger", "label-success"];
    var reportStatusOfMaterialControlDepartment = ['无状态', '正常提报', '暂不提报', '部分提报'];
    var reportStatusOfMaterialControlDepartmentColor = ['label-default', 'label-info', 'label-primary', 'label-warning'];

    /** 打开编辑模态框, 回显数据 */
    function openEditModal(id) {
        js.post({
            url: ctx + "overview/state/id",
            data: {
                id: id
            },
            success: function (result) {
                $("#editForm").fillData(result);
                js.modal.open("modal-edit");
            }
        })
    }

    /** 打开编辑模态框, 回显数据 */
    function openEditMaterialControlModal(id) {
        js.post({
            url: ctx + "overview/state/id",
            data: {
                id: id
            },
            success: function (result) {
                $("#editMcForm").fillData(result);
                js.modal.open("modal-mc-edit");
            }
        })
    }

    $(function () {

        /** 初始化表格 */
        table = js.table.init({
            url: ctx + "overview/state/list",
            columns: [
                {
                    title: '序号', field: 'proId', width: '40',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                {title: "项目编号", field: 'code'},
                {title: "项目名称", field: 'name',width: '280'},
                {title: "数量", field: 'num'},
                /*{
                    title: "剩余金额", field: 'overMoney',
                    formatter: function (value, row, index) {
                        if (hasP("overview:amount:view")) {
                            return value;
                        }
                    }
                },*/
                // {
                //     title: "生产状态", field: 'status',
                //     formatter: function (value, row, index) {
                //         if (value === 1) {
                //             return '<span class="badge ' + color1[value] + '">' + '未完成' + '</span> ';
                //         } else if (value === 2) {
                //             return '<span class="badge ' + color1[value] + '">' + '未完成' + '</span> ';
                //         } else if (value === 3) {
                //             return '<span class="badge ' + color1[value] + '">' + '项目暂停' + '</span> ';
                //         } else if (value === 4) {
                //             return '<span class="badge ' + color1[value] + '">' + '已完成' + '</span> ';
                //         } else if (value === 0) {
                //             return '<span class="badge ' + color1[value] + '">' + '项目取消' + '</span> ';
                //         }
                //     }
                // },
                {
                    title: "生产状态", field: 'proProductionStatus',
                    formatter: function (value, row, index) {
                        let s = 0;
                        if (value) {
                            s = value;
                        }
                        return '<span class="badge ' + color[s] + '">' + state[s] + '</span> ';
                    }
                },
                {
                    title: "物控科<br>原料状态", field: 'proMatStatus',
                    formatter: function (value, row, index) {
                        if (value == null) {
                            value = 0;
                        }
                        return '<span class="badge ' + reportStatusOfMaterialControlDepartmentColor[value] + '">' + reportStatusOfMaterialControlDepartment[value] + '</span> ';
                    }
                },

                {
                    title: "物控科<br>外购件状态", field: 'proPurStatus',
                    formatter: function (value, row, index) {
                        if (value == null) {
                            value = 0;
                        }
                        return '<span class="badge ' + reportStatusOfMaterialControlDepartmentColor[value] + '">' + reportStatusOfMaterialControlDepartment[value] + '</span> ';
                    }
                },

                {
                    title: "物控科<br>外协件状态", field: 'proSubcontractStatus',
                    formatter: function (value, row, index) {
                        if (value == null) {
                            value = 0;
                        }
                        return '<span class="badge ' + reportStatusOfMaterialControlDepartmentColor[value] + '">' + reportStatusOfMaterialControlDepartment[value] + '</span> ';
                    }
                },
                {
                    title: "外购需求日期", field: 'proPurchaseDemandDate',
                    formatter: function (value, row, index) {
                        if (value == null) {
                            value = '';
                        }
                        return value;
                    }
                },
                {title: "备注", field: 'proRemark'},
                {
                    title: "操作",
                    width: '80',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (hasP("overview:project:edit")) {
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openEditModal(' + row.id + ')"> 生产状态修改</a> ');
                        }
                        if(hasP('overview:projectmc:edit')){
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openEditMaterialControlModal(' + row.id + ')"> 物控状态修改</a> ');
                        }
                        return actions.join('');
                    }
                }
            ]
        });

        /**
         * 表格搜索
         */
        $("#btn-search").click(function () {
            js.table.search(table);
        });

        /** 修改提报计划 确定按钮点击事件 */
        $("#btn-edit").click(function () {
            js.submit({
                url: ctx + "overview/state/edit",
                data: new FormData($("#editForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                        js.modal.hide("modal-edit");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });
        /** 修改提报计划 确定按钮点击事件 */
        $("#btn-mc-edit").click(function () {
            js.submit({
                url: ctx + "overview/state/saveMcData",
                data: new FormData($("#editMcForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                        js.modal.hide("modal-mc-edit");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });
    });

</script>
</body>
</html>
